package com.StartGame;

import android.graphics.*;
import android.graphics.Bitmap.Config;

public class Slice {
	public int x, y; // ���� ��ġ
	public Bitmap imgPic; // Slice �̹���

	private int s; // slice ũ��

	// -------------------------------------
	// ���� - �����ȣ, �迭 ÷��
	// -------------------------------------
	public Slice(int sliceNum, int pos) {
		s = MyGameView.sSize; // Slice Size

		// �迭 ��ȣ�� View�� ��ǥ�� ��ȯ
		x = pos % MyGameView.Cnt * s + MyGameView.mgnLeft;
		y = pos / MyGameView.Cnt * s + MyGameView.mgnTop;

		// Slice ��ȣ�� ���� ��ǥ�� ��ȯ
		int px = sliceNum % MyGameView.Cnt * s;
		int py = sliceNum / MyGameView.Cnt * s;

		// ���� �ڸ���
		imgPic = Bitmap.createBitmap(MyGameView.imgOrg, px, py, s, s);
		
		Paint paint = new Paint();
		paint.setAntiAlias(true);

		paint.setStyle(Paint.Style.STROKE);
		paint.setColor(Color.argb(255, 0, 0, 255));

		Canvas canvas = new Canvas();
		canvas.setBitmap(imgPic);
		
		for (int i = 0; i < MyGameView.Cnt; i++) {
			for (int j = 0; j < MyGameView.Cnt; j++) {
				canvas.drawRect(new Rect(MyGameView.mgnLeft + j * s, MyGameView.mgnTop + i * s,
						MyGameView.mgnLeft + j * s + s, MyGameView.mgnTop + i * s + s), paint);
			}
		}
		
	}
}

// ------------------------------------------------------------

// -------------------------------------
// �̵� & �ð� & Stage �����
// -------------------------------------
class Score {
	public Bitmap imgTime; // ��� �ð�
	public Bitmap imgStage; // Stage

	private Bitmap fonts[] = new Bitmap[15];
	private Bitmap imgStg; // 'STAGE' ����
	private int fw, fh, sw; // ���� �� & ����
	private int icoNum = 11;
	private long lastTime;

	// -------------------------------------
	// ����
	// -------------------------------------
	public Score() {
		for (int i = 0; i < 15; i++)
			fonts[i] = BitmapFactory.decodeResource(
					MyGameView.mContext.getResources(), R.drawable.f00 + i);
		imgStg = BitmapFactory.decodeResource(
				MyGameView.mContext.getResources(), R.drawable.f_stage);
		fw = fonts[0].getWidth();
		fh = fonts[0].getHeight();
		sw = imgStg.getWidth();
	}

	// -------------------------------------
	// �ð� �̹���
	// -------------------------------------
	public void MakeTime(long startTime) {
		long curTime = System.currentTimeMillis();
		if (startTime > curTime)
			MyGameView.startTime = startTime = curTime;

		if (curTime - lastTime < 250)
			return;
		lastTime = curTime;
		int time = (int) (curTime - startTime) / 1000;
		int sec = time % 60;
		int min = time / 60 % 60;
		int hour = time / 3600;

		String s = hour + ":" + min + ":" + sec;
		int L = s.length(); // ���ڿ��� ����

		// �� ��Ʈ���� �����
		imgTime = Bitmap.createBitmap(fw * L, fh, Config.ARGB_8888);

		// ��Ʈ�ʿ� �̹����� �׷����� Canvas ��
		Canvas canvas = new Canvas();
		canvas.setBitmap(imgTime);
		for (int i = 0; i < L; i++) {
			int n = (int) s.charAt(i) - 48;
			canvas.drawBitmap(fonts[n], fw * i, 0, null);
		}
	}

	// -------------------------------------
	// Stage �̹���
	// -------------------------------------
	public void MakeStageNum(int stageNum) {
		String s = "" + (stageNum + 1);
		int L = s.length(); // ���ڿ��� ����

		// �� ��Ʈ���� �����
		imgStage = Bitmap.createBitmap(sw + fw * L, fonts[0].getHeight(),
				Config.ARGB_8888);

		// ��Ʈ�ʿ� �̹����� �׷����� Canvas ��
		Canvas canvas = new Canvas();
		canvas.setBitmap(imgStage);

		canvas.drawBitmap(imgStg, 0, 0, null); // 'STAGE'
		for (int i = 0; i < L; i++) { // stageNum
			int n = (int) s.charAt(i) - 48;
			canvas.drawBitmap(fonts[n], sw + fw * i, 0, null);
		}
	}
}
